Skip to content
This repository has been archived by the owner on Jul 26, 2023. It is now read-only.

Use C# sizeof wherever possible #493

Merged
merged 2 commits into from
Jul 4, 2020
Merged

Use C# sizeof wherever possible #493

merged 2 commits into from
Jul 4, 2020

Conversation

AArnott
Copy link
Collaborator

@AArnott AArnott commented Jul 4, 2020

sizeof(T) is much faster than Marshal.SizeOf<T>, but it can only be safely used when T is a blittable type. This means all members are value types and have no MarshalAs attribute on them. This rule is recursive for all members.

Closes #475

@AArnott
Copy link
Collaborator Author

AArnott commented Jul 4, 2020

CC: @jkotas

Copy link
Member

@jkotas jkotas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

`sizeof(T)` is much faster than `Marshal.SizeOf<T>`, but it can only be safely used when `T` is a blittable type. This means all members are value types and have no `MarshalAs` attribute on them. This rule is recursive for all members.

Closes #475
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Replace our use of Marshal.SizeOf with C# sizeof keyword
2 participants